<?php

namespace App\Repository;

use App\Entity\Subscribe;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @method Subscribe|null find($id, $lockMode = null, $lockVersion = null)
 * @method Subscribe|null findOneBy(array $criteria, array $orderBy = null)
 * @method Subscribe[]    findAll()
 * @method Subscribe[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class SubscribeRepository extends ServiceEntityRepository {

    public function __construct (ManagerRegistry $registry) {
        parent::__construct($registry, Subscribe::class);
    }

    /**
     * 获取所有订阅邮箱
     * @return array
     */
    public function getAllEmail () {
        $result = [];

        $items = $this->createQueryBuilder('s')
            ->select('s.email')
            ->getQuery()
            ->getResult();
        foreach ($items as $item) {
            array_push($result, $item['email']);
        }

        return $result;
    }
}
